<?php
/**
 * Object Relational Persistence Mapping Class for table: encounter_common_info
 *
 * @package	com.athena
 * @author	LHV
 */
class EncounterCommonInfo extends ORDataObject {

	/**#@+
	 * Fields of table: encounter_common_info mapped to class members
	 */
	var $encounter_common_info_id		= '';
	var $medical_record_id		= '';
	var $left_cva		= '';
	var $left_ucva		= '';
	var $right_cva		= '';
	var $right_ucva		= '';
	var $left_javal_k1		= '';
	var $left_javal_k2		= '';
	var $right_javal_k1		= '';
	var $right_javal_k2		= '';
	var $both_eyesight		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'encounter_common_info';

	/**
	 * Primary Key
	 */
	var $_key = 'encounter_common_info_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'EncounterCommonInfo';

	/**
	 * Handle instantiation
	 */
	function EncounterCommonInfo() {
		parent::ORDataObject();
	}

	public function setup($id = 0){
		$this->set('id',$id);
		if($id>0){
			$this->populate();
		}
	}
	
	public function populate(){
		parent::populate('encounter_common_info_id');
	}
	
	public function setData($record_id, $left_javal_k1, $left_javal_k2,
		$right_javal_k1, $right_javal_k2, $left_cva, $left_ucva, $right_cva,
		$right_ucva, $both_eyesight){
		$data	=	array(
			'medical_record_id'		=>	$record_id,
			'left_javal_k1'			=>	$left_javal_k1,
			'left_javal_k2'			=>	$left_javal_k2,
			'right_javal_k1'		=>	$right_javal_k1,
			'right_javal_k2'		=>	$right_javal_k2,
			'left_cva'				=>	$left_cva,
			'left_ucva'				=>	$left_ucva,
			'right_cva'				=>	$right_cva,
			'right_ucva'			=>	$right_ucva,
			'both_eyesight'			=>	$both_eyesight
		);
		$this->populateArray($data);
	}
	
	public function setCvData($record_id, $left_cva, $left_ucva, $right_cva, $right_ucva, $both_eyesight) {
		$data	=	array(
			'medical_record_id'		=>	$record_id,
			'left_javal_k1'			=>	$this->left_javal_k1,
			'left_javal_k2'			=>	$this->left_javal_k2,
			'right_javal_k1'		=>	$this->right_javal_k1,
			'right_javal_k2'		=>	$this->right_javal_k2,
			'left_cva'				=>	$left_cva,
			'left_ucva'				=>	$left_ucva,
			'right_cva'				=>	$right_cva,
			'right_ucva'			=>	$right_ucva,
			'both_eyesight'			=>	$both_eyesight
		);
		$this->populateArray($data);
	}
	
	public function setId($id) {
		$this->encounter_common_info_id = $id;
	}
	
	public function getId() {
		return $this->encounter_common_info_id;
	}
	
	public function getLeftJavalK1(){
		return $this->left_javal_k1;
	}
	
	public function getRightJavalK1(){
		return $this->right_javal_k1;
	}

	public function getLeftJavalK2(){
		return $this->left_javal_k2;
	}
	
	public function getRightJavalK2(){
		return $this->right_javal_k2;
	}
	
	public function getLeftCVA(){
		return $this->left_cva;
	}
	
	public function getRightCVA(){
		return $this->right_cva;
	}		
	
	public function getLeftUCVA(){
		return $this->left_ucva;
	}
	
	public function getRightUCVA(){
		return $this->right_ucva;
	}
	
	public function getBothEyesight(){
		return $this->both_eyesight;
	}
	
	public function getIdFromRecordId($recordId) {
		$sql = "SELECT encounter_common_info_id AS id FROM $this->_table WHERE medical_record_id = $recordId";
		$res = $this->_execute($sql);
		if (empty($res) || $res->fields['id'] == '') {
			return 0;
		}
		return $res->fields['id'];
	}
	
	public function getObjectFromRecordId($recordId) {
		
		$sql = "SELECT $this->_key FROM $this->_table WHERE medical_record_id = $recordId";
		$res = $this->_execute($sql);
		
		$obj = ORDataObject::factory('EncounterCommonInfo');
		if (!$res->EOF) {
			$obj->setup($res->fields[$this->_key]);
		}
		return $obj;						
	}
}
?>
